//
//  FPCitiesModel.m
//  FinanceProject
//
//  Created by 陈显摆 on 2025/4/23.
//

#import "FPCitiesModel.h"

@implementation FPCitiesChild

+ (JSONKeyMapper *)keyMapper {
    
    return [[JSONKeyMapper alloc] initWithModelToJSONDictionary:@{@"ID" : @"id"}];
}

+ (BOOL)propertyIsOptional:(NSString *)propertyName {
    
    return YES;
}

@end

@implementation FPCitiesModel

+ (JSONKeyMapper *)keyMapper {
    
    return [[JSONKeyMapper alloc] initWithModelToJSONDictionary:@{@"ID" : @"id"}];
}

+ (BOOL)propertyIsOptional:(NSString *)propertyName {
    
    return YES;
}


+ (void)getCitiesSuccess:(void (^)(NSArray * _Nonnull))success failure:(void (^)(NSError * _Nonnull))failure {
    
    NSString *path = [[NSBundle mainBundle] pathForResource:@"Address" ofType:@"json"];
    NSData *data = [NSData dataWithContentsOfFile:path];

    NSError *error = nil;
    NSArray *provinces = [FPCitiesModel arrayOfModelsFromData:data error:&error];

    if (error) {
        
//        NSLog(@"解析失败: %@", error.localizedDescription);
    }
    else {
    
        for (FPCitiesModel *province in provinces) {
            
//            NSLog(@"省份: %@", province.provinceName);
            
            for (FPCitiesChild *city in province.cityChild) {
            
//                NSLog(@" - 城市: %@", city.districtName);
            }
        }
    }
    
    if (success) {
        
        success(provinces);
    }
}


@end
